

using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;
using EntityLayer;
using DataLayer;
using System.Data;
using InfraStructureLayer;

namespace BusinessLayer
{
	public class busPhotos:BusinessBase
	{
		public busPhotos() : base()
		{
		}
		#region  Code Factory Generated Methods


        public DataTable SelectPhotos()
        {
            try
            {
                datPhotos insDatPhotos = new datPhotos();
                DbConnector insDbConnector = new DbConnector();
                return insDatPhotos.SelectPhotos(insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
        public void SelectPhotosByPhotoId(entPhotos parEntPhotos)
        {
            try
            {
                datPhotos insDatPhotos = new datPhotos();
                DbConnector insDbConnector = new DbConnector();
                insDatPhotos.SelectPhotosByPhotoId(parEntPhotos, insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
		
		#endregion
        public void InsertPhotos(entPhotos parEntPhotos)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datPhotos insDatPhotos = new datPhotos();
                insDatPhotos.InsertPhotos(parEntPhotos, insDbConnector);
                datPhotoContents insDatPhotoContents = new datPhotoContents();
                foreach (entPhotoContents insEntPhotoContents in parEntPhotos.PhotoContentsInsert)
                {
                    insEntPhotoContents.PhotoId = parEntPhotos.PhotoId;
                    insDatPhotoContents.InsertPhotoContents(insEntPhotoContents, insDbConnector);
                }
                foreach (entPhotoContents insEntPhotoContents in parEntPhotos.PhotoContentsUpdate)
                {
                    insEntPhotoContents.PhotoId = parEntPhotos.PhotoId;
                    insDatPhotoContents.UpdatePhotoContentsByPhotoContentId(insEntPhotoContents, insDbConnector);
                }
                foreach (entPhotoContents insEntPhotoContents in parEntPhotos.PhotoContentsDelete)
                {
                    insDatPhotoContents.DeletePhotoContentsByPhotoContentId(insEntPhotoContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void UpdatePhotosByPhotoId(entPhotos parEntPhotos)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {

                insDbConnector.BeginTransaction();
                datPhotos insDatPhotos = new datPhotos();
                insDatPhotos.UpdatePhotosByPhotoId(parEntPhotos, insDbConnector);
                datPhotoContents insDatPhotoContents = new datPhotoContents();
                foreach (entPhotoContents insEntPhotoContents in parEntPhotos.PhotoContentsInsert)
                {
                    insEntPhotoContents.PhotoId = parEntPhotos.PhotoId;
                    insDatPhotoContents.InsertPhotoContents(insEntPhotoContents, insDbConnector);
                }
                foreach (entPhotoContents insEntPhotoContents in parEntPhotos.PhotoContentsUpdate)
                {
                    insEntPhotoContents.PhotoId = parEntPhotos.PhotoId;
                    insDatPhotoContents.UpdatePhotoContentsByPhotoContentId(insEntPhotoContents, insDbConnector);
                }
                foreach (entPhotoContents insEntPhotoContents in parEntPhotos.PhotoContentsDelete)
                {
                    insDatPhotoContents.DeletePhotoContentsByPhotoContentId(insEntPhotoContents, insDbConnector);
                }
                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public void DeletePhotosByPhotoId(entPhotos parEntPhotos)
        {
            DbConnector insDbConnector = new DbConnector();
            try
            {
                insDbConnector.BeginTransaction();

                datPhotoContents insDatPhotoContents = new datPhotoContents();
                entPhotoContents insEntPhotoContents = new entPhotoContents();
                insEntPhotoContents.PhotoId = parEntPhotos.PhotoId;
                insDatPhotoContents.DeletePhotoContentsByPhotoId(insEntPhotoContents, insDbConnector);

                datPhotos insDatPhotos = new datPhotos();
                insDatPhotos.DeletePhotosByPhotoId(parEntPhotos, insDbConnector);

                insDbConnector.CommitTransaction();
            }
            catch (SFException ex)
            {
                insDbConnector.RollbackTransaction();
                this.ErrorMessage = ex.Message;
            }
            catch (Exception ex)
            {
                insDbConnector.RollbackTransaction();
                throw new SFUnHandledException(ex);
            }
        }
        public DataTable SelectPhotosRandom()
        {
            DbConnector insDbConnector = new DbConnector();

            try
            {
                datPhotos insDatPhotos = new datPhotos();
                return insDatPhotos.SelectPhotosRandom(insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
        public DataTable SelectPhotosByLanguageId()
        {
            try
            {
                datPhotos insDatPhotos = new datPhotos();
                DbConnector insDbConnector = new DbConnector();
                return insDatPhotos.SelectPhotosByLanguageId(insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
        public DataTable SelectPhotosByLanguageIdAndPhotoAlbumId(entPhotos parEntPhotos)
        {
            try
            {
                datPhotos insDatPhotos = new datPhotos();
                DbConnector insDbConnector = new DbConnector();
                return insDatPhotos.SelectPhotosByLanguageIdAndPhotoAlbumId(parEntPhotos,insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
        public DataTable SelectPhotosByLanguageIdAndPhotoId(entPhotos parEntPhotos)
        {
            try
            {
                datPhotos insDatPhotos = new datPhotos();
                DbConnector insDbConnector = new DbConnector();
                return insDatPhotos.SelectPhotosByLanguageIdAndPhotoId(parEntPhotos, insDbConnector);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
	}
}